package com.meituan.service.impl;

import com.meituan.dao.OrderMapper;
import com.meituan.dao.StoresDao;
import com.meituan.pojo.dto.OrderMessageDto;
import com.meituan.pojo.resp.BaseOrderResp;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
* 订单表service实现类
* */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    //根据三个id查询是否有相同商品订单
    @Override
    public List<BaseOrderResp> findByAllId(int uid, int sid, int gid) {
        List<BaseOrderResp> byAllId = orderMapper.findByAllId(uid, sid, gid);
        return byAllId;
    }
    //根据订单id修改数量
    @Override
    public boolean updateGnum(int oid, int gnum_new) {
        int i = orderMapper.updateGnum(oid, gnum_new);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteByOid(Integer oid) {
        int i = orderMapper.deleteByOid(oid);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public List<StoresDao> findShopping(int uid) {
        List<StoresDao> shopping = orderMapper.findShopping(uid);
        return shopping;
    }

    @Override
    public List<StoresDao> findHistoryShopping(int uid) {
        List<StoresDao> shopping = orderMapper.findHistoryShopping(uid);
        return shopping;
    }

    @Override
    public OrderMessageDto fingOneOrder(Integer uid,Integer sid, Integer gid) {
        OrderMessageDto oneOrder = orderMapper.findOneOrder(uid,sid,gid);
        return oneOrder;
    }

    @Override
    public boolean payComplete(int oid) {
        int i = orderMapper.payComplete(oid);
        if (i>0){
            return true;
        }
        return false;
    }
}
